import { Input, Modal, Tabs, Menu, Card, Form, Button } from 'antd'
import { useState, useEffect, useRef } from 'react'



import ApprovalInformationList from '../ApprovalInformationList';
import DangerReport from '../DangerReport';
import InfoFeedback from '../InfoFeedback';
import FetchHelper from "../../../../../../../utils/helper/fetch-helper";
import MapPoint from '../../../../../../framework/MapPoint';



export default function DangerDel(props) {
    const { item } = props;
    const { data, setData } = props
    const from_xxfk = useRef()



    const onClick = ({ item, key, keyPath, domEvent }) => {
        setData(key)
        //console.log(key,item);
    };
    const [xxfkItem, setXxfkItem] = useState();
    const [open_addXxfk, setOpen_addXxfk] = useState(false);

    //决定新增还是修改
    const [getORpost, setGetORpost] = useState();




    const items = [
        {
            label: '信息反馈',
            key: '1',
            //icon: <MailOutlined />,
        },
        {
            label: '调查管理',
            key: '2',
            // icon: <AppstoreOutlined />,
            //disabled: true,
        },
        {
            label: '排查治理',
            key: '3',
            // icon: <AppstoreOutlined />,
            //disabled: true,
        },
        {
            label: '灾情直报',
            key: '4',
            // icon: <AppstoreOutlined />,
            //disabled: true,
        },
        {
            label: '隐患点管理',
            key: '5',
            // icon: <AppstoreOutlined />,
            //disabled: true,
        },
        {
            label: '辅助信息',
            key: '6',
            // icon: <AppstoreOutlined />,
            //disabled: true,
        },
       
    ]

    useEffect(() => {
        if (item?.id) {
            FetchHelper.getJson(`/admin-api/ybyj/rwb/list`, { rwid: item?.id }).then(resp => {
                console.log("123112", resp)
                setXxfkItem(resp)
            })
        }

    }, [item, open_addXxfk, getORpost])
    const [formData, setFormData] = useState({
        dcmb: '',
        dcmd: ''
    });
    const handleReset = () => {
        setFormData({
            dcmb: '',
            dcmd: ''
        });
    };

    const xxfkOnFinish = (value) => {
        if (getORpost.getorpost === 1) {

            FetchHelper.putJson(`/admin-api/ybyj/rwb`, { ...getORpost.currentValue, ...value }).then(resp => { }).catch(err => { alert("上传失败") })
            from_xxfk.current.resetFields(); // 重置表单字段的值
        } else if (getORpost.getorpost === 2) {
            value.rwlx = '信息反馈';
            value.rwid = item?.id;
            value.bz = `站点：${item?.zdmc}\n标题：${item?.yjbt}\n`
            value.geom = item?.geom;
            value.iswc = "否"
            console.log('value\n', 2)
            FetchHelper.postJson(`/admin-api/ybyj/rwb`, value).then(resp => { }).catch(err => { alert("上传失败") })
            from_xxfk.current.resetFields(); // 重置表单字段的值
        }
        setOpen_addXxfk(false);
    }
    return <div >

        <Modal wrapClassName='modal-main' title="待办任务" open={!!item} {...props} onOk={e => {
            props.onOk?.();
        }} width={800} bodyStyle={{
            //height: 400
        }} afterClose={() => { setXxfkItem(null) }}>
            {/*  <Tabs defaultActiveKey="1" items={items} onChange={onChange} /> */}
            <Menu defaultOpenKeys='1' onClick={onClick} mode="horizontal" items={items} />
            <div style={{
                width: 750,
                height: 400,
                //backgroundColor:'red',
            }}>
                {/* 信息反馈 */}
                {data === '1' && <Card style={{
                    width: "100%",
                    height: "100%",
                    overflow: "auto"
                    //backgroundColor:'red',
                }}><div style={{ display: !open_addXxfk ? 'block' : 'none' }}><div style={{ color: 'GrayText' }}>{xxfkItem?.total !== 0 ? xxfkItem?.rows.map((currentValue, index, array) => {
                    console.log('@@@@@@@', currentValue)
                    return <>
                        <Card style={{ position: 'relative', marginTop: 10 }}>
                            <Button type='link' onClick={() => { setOpen_addXxfk(true); from_xxfk.current.setFieldsValue(currentValue); setGetORpost({ getorpost: 1, currentValue: currentValue }) }}>反馈信息_{index + 1}</Button>
                            <p style={{ whiteSpace: 'pre-line' }}>{currentValue?.bz}</p>
                            <Button type='link' style={{ position: 'absolute', right: 10, bottom: 10, }} onClick={() => { }}>{currentValue.iswc === "完成" ? "已完成" :currentValue.iswc === "查看" ?'已查看': "待审批"}</Button>
                        </Card>
                    </>
                }) : '暂未建立信息反馈任务'}
                </div>
                        <h3><Button type='link' onClick={() => { setOpen_addXxfk(true); setGetORpost({ getorpost: 2 }) }}>建立信息反馈任务</Button></h3></div>

                    <div style={{ display: open_addXxfk ? 'block' : 'none' }}>
                        <Form ref={from_xxfk} onFinish={xxfkOnFinish} initialValues={formData}>
                            <h1>信息反馈</h1>
                            <Form.Item label='预警信息调查反馈' name='dcmb' rules={[{ required: true, }]}>
                                <Input.TextArea rows={1} placeholder='' value='' />
                            </Form.Item>
                            {/* <Form.Item label='图片' name='' rules={[{}]}>
                            <Input.TextArea rows={1} placeholder='' value='' />
                        </Form.Item>
                        <Form.Item label='视频' name='' rules={[{}]}>
                            <Input.TextArea rows={1} placeholder='' value='' />
                        </Form.Item> */}
                            <Form.Item label='应对方法反馈' name='dcmd' rules={[{ required: true, }]}>
                                <Input.TextArea rows={1} placeholder='' value='' />
                            </Form.Item>
                            <Form.Item label='应对方法反馈' name='geom' rules={[{ required: true, }]}>
                                <MapPoint></MapPoint>
                            </Form.Item>
                            <div className="layout-h">
                                <Button className="btn1" type="primary"
                                    htmlType="submit"
                                //onClick={()=>setOpen_addXxfk(false)}
                                >确定</Button>

                                <Button onClick={() => { setOpen_addXxfk(false); from_xxfk.current.resetFields(); }} className="btn2">返回</Button>
                            </div>
                        </Form>
                    </div>
                </Card>}

                {/* 调查管理 */}


                {/* 排查治理 */}


                {/* 排查治理 */}


                {data==='6'&&<InfoFeedback data={data}/>}
                       {data!=='6'&&data!=='1'&& <ApprovalInformationList data={data} item={item}/>}
            </div>
            {/* <Input.TextArea rows={10} placeholder='隐患解除原因' /> */}
        </Modal>

    </div>

}